<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/4/11 0011
 * Time: 下午 12:45
 */

namespace Admin\Controller;

use Think\Controller;
use Think\Upload;

/**
 * 用于制作图片上传
 * Class UploadfiyController
 * @package Admin\Controller
 */
class UploadController extends Controller{

    //用于上传文件
    public function upload(){
        //上传驱动
        $driver = C('UPLOADFILE');
        //实例化上传类
        $upload = new Upload($driver);
//        dump($upload);
//        exit;
        //获取上传数据
        $info = $upload->upload();
        if($driver['driver'] == 'Qiniu'){
            //如果上传驱动为七牛云
            $imgurl = $info['file']['savepath'].$info['file']['savename'];
            $imgurl = str_replace('/','_',$imgurl);
        } else {
            //拼接url
            $imgurl = $info['file']['savepath'].$info['file']['savename'];
        }

       //构建要返回的数据
        $return = array(
           'status'=>$imgurl?1:0,
           'imgurl'=>$imgurl,
           'msg'=>$upload->getError(),
       );
        $this->ajaxReturn($return);
    }
}